package com.ruiyin.controller;

import java.net.URLDecoder;
import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.ruiyin.bean.SysUser;
import com.ruiyin.bean.Weixinparameters;
import com.ruiyin.interceptor.BaseInterceptor;
import com.ruiyin.service.LoginService;

@Before(BaseInterceptor.class)
public class LoginController extends Controller{
	
	public void index() {
		//render("index1.jsp");
		this.render("login/login.jsp");
	}
	
	public void login() {
		try {
			String code =getPara("userInfo");
		    Weixinparameters weixin = getModel(Weixinparameters.class);
			SysUser sysUser = getModel(SysUser.class);
			LoginService ls =  new LoginService();
			sysUser= ls.login(sysUser);
			setAttr("sysUser", sysUser);
			int pageNumber =1;
			try {
				 pageNumber =getParaToInt(0);
			} catch (Exception e) {
				pageNumber=1;
			}
			Page<Record> sysuserList =  ls.paginate(pageNumber, 3);
			setAttr("sysuserList", (List<Record>)sysuserList.getList());
			
			setAttr("pageNumber", sysuserList.getPageNumber());
			setAttr("pageSize", sysuserList.getPageSize());
			setAttr("totalPage", sysuserList.getTotalPage());
			setAttr("totalRow", sysuserList.getTotalRow());
			setAttr("pageUrl", "login/login/");
			
		} catch (Exception e) {
			e.printStackTrace();
			this.render("login.jsp");
		}
		this.renderJsp("user/User_list.jsp");
	} 
	
	public void save(){
		SysUser users = new SysUser();
		users.set("id", "users_sequence.nextval");//nextval必须小写
		users.set("username", "张三");
		users.set("pwd", "sdfsdfs");
		users.save();
	}
	
	public void loginajax() {
		System.out.println("username:"+getPara(0));
		System.out.println("pwd:"+getPara(1));
		setAttr("msg", "success");
		 renderJson();
	}
}
